package com.kurumi.medical.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kurumi.medical.pojo.HospitalHoliday;
import com.kurumi.medical.service.HolidayService;
import com.kurumi.medical.util.JsonUtils;
import com.kurumi.medical.util.Result;

@Controller
@RequestMapping("/holiday")
public class HolidayController {
	
	@Autowired
	private HolidayService holidayService;
	
	@RequestMapping("/getHolidays")
	public String getHolidays(Model model){
		List<HospitalHoliday> holidays = holidayService.getHolidays();
		model.addAttribute("holidays", JsonUtils.objectToJson(holidays));
		return "holiday/setholiday";
	}
	

	@ResponseBody
	@RequestMapping("/setHoliday")
	public Result setHoliday(String date,Integer id){
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");   
		Result flag = new Result(false,"");
		try {
			Date holidayDate = format.parse(date);
			
			 flag = holidayService.setHoliday(holidayDate, id);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}

}
